{# SPDX-FileCopyrightText: © 2014-2017 Siemens AG

   SPDX-License-Identifier: FSFAP
#}
{% extends "include/base.html.twig" %}
{% block styles %}
  {{ parent() }}
  <link rel="stylesheet" href="css/highlights.css"/>
{% endblock %}

{% block content %}

<table class="semibordered" id="licenseCandidateTbl" width="100%" cellpadding="0">
  <thead>
    <tr>
      <th width="5%"></th>
      <th width="10%"></th>
      <th width="10%"></th>
      <th width="15%"></th>
      <th width="40%"></th>
      <th width="10%"></th>
      <th width="10%"></th>
    </tr>
  </thead>
</table>
  <br/><br/>
  
{% endblock %}

{% block foot %}
  {{ parent() }}
  <script src="scripts/jquery.dataTables.min.js" type="text/javascript"></script>
  <script src="scripts/jquery.dataTables.select.js" type="text/javascript"></script>
  <script src="scripts/jquery-ui.js" type="text/javascript"></script>
  <script type="text/javascript">
    function createBrowseTable() {
    tableColumns = [
    {"sTitle": "{{ "Edit"|trans }}", "sClass": "center", "bSearchable": false},
    {"sTitle": "{{ "SPDX ID"|trans }}", "sClass": "center", "bSearchable": true},
    {"sTitle": "{{ "Shortname"|trans }}", "sClass": "center", "bSearchable": true},
    {"sTitle": "{{ "Fullname"|trans }}", "sClass": "center", "bSearchable": false},
    {"sTitle": "{{ "Text"|trans }}", "sClass": "left", "bSearchable": false},
    {"sTitle": "{{ "Group"|trans }}", "sClass": "center", "bSearchable": true},
    {"sTitle": "{{ "Delete"|trans }}", "sClass": "center", "bSearchable": false}
  ];

  tableSorting = [[2, "asc"]];

  dataTableConfig =
      {
        "aoColumns": tableColumns,
        "aaSorting": tableSorting,
        "iDisplayLength": 20,
        "aaData": {{ aaData }},
        "sPaginationType": "listbox",
        "bStateSave": true
      };

    var otable = $('#licenseCandidateTbl').dataTable(dataTableConfig);
    return otable;
  }
    
  function deleteCandidate(rfPk) {
    var mainDiv = "<div></div>";
    var confrimMessage = "Remove this license from candidate license list?";
    $(mainDiv).html(confrimMessage).dialog({
      title: "Please Confrim",
      resizable: false,
      modal: true,
      buttons: {
        "Ok": function() {
          $(this).dialog("close");
          $.ajax({
            type: 'POST',
            dataType: 'text',
            url: '?mod=admin_license_candidate&do=deletecandidate',
            data: { rf : rfPk },
            success: function(dataOnSuccess) {
              if(dataOnSuccess == "true"){
                $("#deletecandidate" + rfPk).closest("tr").hide();
              }else{
                $(mainDiv).html(dataOnSuccess).dialog({
                  title: "Cannot remove license, Because it is in use at",
                  width:'auto',
                  height:'auto',
                  modal: true,
                  buttons: {
                    "Close": function() {
                      $(this).dialog("close");
                    }
                  }
                });
              }
            },
            error: function() { alert('error'); }
          });
          },
        Cancel: function() {
          $(this).dialog("close");
        }
      }
    });
  }

  $(document).ready(function () {
    createBrowseTable();
  });
    
  </script>
{% endblock %}
